package com.gewu.core.db

import android.content.Context
import android.util.Log
import androidx.room.*
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.gewu.bluetoothflow.db.DeviceInfoBean
import com.gewu.bluetoothflow.db.DeviceInfoBeanDao


@Database(
    entities = [DeviceInfoBean::class ],
    version = 1,
    exportSchema = false
)
 abstract class GwAppDataBase: RoomDatabase() {

     abstract fun deviceInfoDao(): DeviceInfoBeanDao
//     abstract fun deviceInfoDao(): DeviceInfoDao
//     abstract fun environmentDao(): EnvironmentDao
//     abstract fun deviceAlarmDao(): DeviceAlarmDao
//     abstract fun alarmLinkageDao(): AlarmLinkageDao
//     abstract fun dragViewInfosDao(): DragViewInfosDao




companion object {
    var INSTANCE:GwAppDataBase? = null
    private val migrations = arrayOf(
        object: Migration(1, 2) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL("DROP TABLE IF EXISTS `ScrollTextData`")
                database.execSQL("CREATE TABLE IF NOT EXISTS `ScrollTextData` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `bgColor` TEXT, `content` TEXT, `endTime` INTEGER, `positionType` INTEGER NOT NULL, `textColor` TEXT, `startTime` INTEGER)")
            }
        }
    )

    fun newInstance(context: Context): GwAppDataBase {
        return INSTANCE ?: synchronized(this) {
            val instance = Room.databaseBuilder(
                context.applicationContext,
                GwAppDataBase::class.java,
                "bletoothflow.db"
            )  //.addMigrations(*migrations)
                .fallbackToDestructiveMigrationOnDowngrade() //降级数据库版本时 重建数据库
                .build()
            INSTANCE = instance
            instance
        }
    }
}



}